<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" session="false" %><%@
include file="/WEB-INF/jspf/import.jspf" %>
<!doctype HTML>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
        <title> 车友会金币兑换-兑换信息</title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta name="author" content="xieyongshuang_gz zhongqingbiao_gz"/>
        <link rel="stylesheet" type="text/css" href="http://js.3conline.com/wap/pcauto/2014/touch/club/club.css">
    </head>
    <body class="g-doc">
        <!--栏目计数器/文章计数器-->
         <jsp:include page="/template/wap/common/counter.jspf">
            <jsp:param name="channel" value="7841" />
        </jsp:include>
         <%@include file="../common/intf6007.html" %>
        <!-- 公共头部 -->
        <div class="g-hd">
            <a href="http://m.pcauto.com.cn" class="header-home" title="太平洋汽车网"></a>
            <div class="header-title">
                <span class="header-title-nav">
                    <a href="${WAPROOT}/">车友会</a> 
                    &gt; <a href="${WAPROOT}/duihuan/">金币兑换</a> &gt; 兑换信息
                </span>
            </div>
        </div>
        <div class="g-gifelist-item" style="background: #f5f6f8">
            <div class="gifelist-info" style="width:220px">
                <img src="${gift.giftUrl60x60}">
                <p class="tit">${fn:escapeXml(gift.name)}</p>
                <div class="des"><p class="gold">${gift.gold}</p></div>
            </div>             
        </div>
        <div class="g-gife-form">
              <div class="ipt-item" id="numClass"><!-- ipt-item-err -->
                <input type="text" placeholder="兑换数量" name="num" id="num"/>
            </div>
            <div class="ipt-item" id="trueNameClass"><!-- ipt-item-err -->
                <input type="text" placeholder="真实姓名" name="trueName" id="trueName"/>
                <input type="hidden" name="province" /><input type="hidden" name="city"/>
            </div>
            <div class="ipt-item" id="cityIdClass">
                <span>所在城市</span><select name="cityId"  id="cityId"><option value="" selected></option></select>
            </div>
            <div class="ipt-item" id="addressClass">
                <input type="text" placeholder="详细地址" name="address" id="address"/>
            </div>
            <div class="ipt-item" id="postcodeClass">
                <input type="text" placeholder="邮政编码" name="postcode" id="postcode"/>
            </div>
            <div class="ipt-item" id="phoneClass">
                <input type="text" placeholder="手机号码" name="phone" id="phone"/>
            </div>
            <div class="btn" id="duihuan">确定兑换</div>
        </div>


        <%@include file="/template/wap/gift/giftResult.jsp" %>

        <div id="Jfoot" class="g-footer">
            <!-- 公共底部 -->
          <%@include file="../common/intf5987.html" %>
        </div>
        <script type="text/javascript" src="http://js.3conline.com/js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript">
            //车友会地区
            var isSend = 0;//是否正在提交中
            var elem_bg=document.getElementById('j-g-mack');
            var elem_pop=document.getElementById('j-g-pop');
            elem_bg.style.height = document.documentElement.clientHeight + 70 + "px";
            var unlogin_elem_bg=document.getElementById('unlogin-j-g-mack');
            var unlogin_elem_pop=document.getElementById('unlogin-j-g-pop');
            unlogin_elem_bg.style.height = document.documentElement.clientHeight + 70 + "px";
            var unJoin_elem_bg=document.getElementById('unJoin-j-g-mack');
            var unJoin_elem_pop=document.getElementById('unJoin-j-g-pop');
            unJoin_elem_bg.style.height = document.documentElement.clientHeight + 70 + "px";
            var message_elem_bg=document.getElementById('message-j-g-mack');
            var message_elem_pop=document.getElementById('message-j-g-pop');
           
            message_elem_bg.style.height = document.documentElement.clientHeight + 70 + "px";
            function loadUserAddress(){
                $.getJSON("${UCROOT}/intf/getAddressByUser.jsp?callback=?",{userId:${user.uid}},function(data){
                    if(data.code==0){
                        loadProvince(data.domicileId);
                        $("#trueName").val(data.realName);
                        $("#address").val(data.address);
                        $("#postcode").val(data.postcode);
                        $("#phone").val(data.telephone);
                    }else{
                        loadProvince(0);
                        $("#truename").val("");
                        $("#address").val("");
                        $("#postcode").val("");
                        $("#phone").val("");
                    }
                });
            }
            function loadProvinceCallback(){
                $("#areaParentTag_cityId option").first().text("省份");
                $("#cityId option").first().text("地区");
            }
            function loadProvince(domicileId){
                $.getScript("${UCROOT}/intf/area.jsp?tag=cityId&selected="+domicileId+"&defaultCityTips=1&success=loadProvinceCallback");
            }
           
            function showPop(giftId){
            	$("#numClass").removeClass("ipt-item-err");
                $("#trueNameClass").removeClass("ipt-item-err");
                $("#cityIdClass").removeClass("ipt-item-err");
                $("#addressClass").removeClass("ipt-item-err");
                $("#postcodeClass").removeClass("ipt-item-err");
                $("#phoneClass").removeClass("ipt-item-err");
               
                var num = $("#num").val();
                var trueName = $("#trueName").val();
                var postcode = $("#postcode").val();
                var phone = $("#phone").val();
                var address = $("#address").val();
                var provinceId = $("#areaParentTag_cityId").find("option:selected").val();
                var cityId = $("#cityId").find("option:selected").val();
                if(num == ""){
                	 $("#numClass").addClass("ipt-item-err");
                     $("#num").attr("placeholder","请填写正确的兑换数量");
                     return;
                }
                if(!(/^[0-9]*$/.test(num))){
                	 $("#numClass").addClass("ipt-item-err");
                     $("#num").attr("placeholder","请填写正确的兑换数量");
            		return;
            	}
                if(trueName==""){
                    $("#trueNameClass").addClass("ipt-item-err");
                    $("#trueName").attr("placeholder","请填写真实姓名");
                    return;
                }
                if(cityId==0 || cityId==undefined || cityId==""){
                    $("#cityIdClass").addClass("ipt-item-err");
                    return;
                }
                if(address==""){
                    $("#addressClass").addClass("ipt-item-err");
                    $("#address").attr("placeholder","请填写地址");
                    return;
                }
                if(postcode==""){
                    $("#postcodeClass").addClass("ipt-item-err");
                    $("#postcode").attr("placeholder","请填写邮政编码");
                    return;
                }
                if(!postcode.match("^\\d{6}$")){
                    $("#postcodeClass").addClass("ipt-item-err");
                    $("#message").html("请填写正确的邮政编码");
                    message_elem_bg.style.display=message_elem_pop.style.display="block"; 
                    return;
                }
                if(phone==""){
                    $("#phoneClass").addClass("ipt-item-err");
                    $("#phone").attr("placeholder","请填写手机号码");
                    return;
                }
                if(!phone.match("^(13|14|15|18|17)[0-9]{9}$")){
                    $("#phoneClass").addClass("ipt-item-err");
                    $("#message").html("请填写正确的手机号码");
                    message_elem_bg.style.display=message_elem_pop.style.display="block"; 
                    return;
                }
                var province = $("#areaParentTag_cityId").find("option:selected").text();
                var city = $("#cityId").find("option:selected").text();
                if(isSend==1){
                    return;
                }
                isSend=1;
                $("#duihuan").html("提交中...");
                $.ajax({
                    type: "POST",
                    url: "${WAPROOT}/gift/createConversion.do",
                    timeout:60000,
                    dataType:"json",
                    data: {
                        giftId:giftId,
                        trueName:trueName,
                        postcode:postcode,
                        phone:phone,
                        address:address,
                        province:province,
                        city:city,
                        num:num},
                    success: function(data){
                        if(data.statusCode==0){  //兑换成功
                            elem_bg.style.display=elem_pop.style.display="block"; 
                        }else if(data.statusCode==1003){ //没有登录

                            unlogin_elem_bg.style.display=unlogin_elem_pop.style.display="block"; 
                        }else if(data.statusCode==1001){//没有加入任何车友会

                            unJoin_elem_bg.style.display=unJoin_elem_pop.style.display="block"; 
                        }else if(data.statusCode==-3){
                            if(data.field == "province" || data.field == "city"){
                                $("#cityIdClass").addClass("ipt-item-err");
                            }else{
                                $("#"+data.field+"Class").addClass("ipt-item-err");
                            }
                            $("#message").html(data.message);
                            message_elem_bg.style.display=message_elem_pop.style.display="block"; 
                        }else{
                            $("#message").html(data.message);
                            message_elem_bg.style.display=message_elem_pop.style.display="block"; 
                        }

                        isSend = 0;
                        $("#duihuan").html("确定兑换");
                    },
                    error:function(){
                        isSend = 0;
                        $("#duihuan").html("确定兑换");
                        alert("提交超时，请检查网络");
							  
                    }
                    	   
                });       
                //elem_bg.style.display=elem_pop.style.display="block";
            }
            function hidePopSuccess(){
                elem_bg.style.display=elem_pop.style.display="none";
                window.location.href="${WAPROOT}/duihuan/";
            }
            function hidePopUnlogin(){
                unlogin_elem_bg.style.display=unlogin_elem_pop.style.display="none";
            }
            function hidePopUnJoin(){
                unJoin_elem_bg.style.display=unJoin_elem_pop.style.display="none";
            }
            function hidePopMessage(){
                message_elem_bg.style.display=message_elem_pop.style.display="none";
            }
           
            document.getElementById("duihuan").onclick=function(){showPop(${gift.giftId});}
            loadUserAddress();
            
          
            $(function(){
            	$("#num").blur(function(){
                	var num = $("#num").val();
                	if(!(/^[0-9]*$/.test(num))){
                		$("#num").val(1);
                		return;
                	}
                });
            })
            
        </script>

    </body>
</html>